﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RenAi.Medical.BLL;
using System.Data;
using RenAi.Medical.Model;

namespace RenAi.Medical.Admin
{
    public partial class UpdateDoxtor : System.Web.UI.Page
    {
        DocBll bll = new DocBll();
        HBKeShiBll hbll = new HBKeShiBll();

        public void LoadDoctor()
        {
            DataTable dt = bll.GetDocByID(this.txtid.Text);
            this.tetname.Text = dt.Rows[0][0].ToString();
            this.txtimg.Text = dt.Rows[0][1].ToString();
            if (dt.Rows[0][2].ToString() == "1")
            {
                this.rbtnyi.Checked = true;
            }
            else
            {
                this.rbtnling.Checked = true;
            }
            this.DropDownList1.SelectedValue = dt.Rows[0][3].ToString();
            this.txtjing.Text = dt.Rows[0][4].ToString();
            this.txtzhuan.Text = dt.Rows[0][5].ToString();
            this.txtsum.Text = dt.Rows[0][6].ToString();
        }
        public void LoadHBKeShi()   //加载所有科室信息，并绑定到下拉列表框中 
        {
            this.DropDownList1.DataSource = hbll.GetHBKeShiAll();
            this.DropDownList1.DataValueField = "HBKeShi_Id";
            this.DropDownList1.DataTextField = "HBKeShi_Name";
            this.DropDownList1.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request.QueryString["id"] != null)
                {
                    this.txtid.Text = Request.QueryString["id"].ToString();

                    LoadHBKeShi();
                    LoadDoctor();
                }
            }
        }

        protected void btnUpt_Click(object sender, EventArgs e)
        {


            Doctor d = new Doctor();
            d.Doctor_Id = int.Parse(this.txtid.Text);
            d.Doctor_Name = this.tetname.Text;
            d.Doctor_Img = this.txtimg.Text;
            d.IFZhuanJia = int.Parse(this.rbtnyi.Checked ? "1" : "0");
            d.HBKeShi_Id = int.Parse(this.DropDownList1.SelectedValue);

            d.Experience = this.txtjing.Text;
            d.Adept = this.txtzhuan.Text;
            d.Num = int.Parse(this.txtsum.Text);

            if (bll.UpDocByID(d) > 0)
            {
                Response.Write("<script>alert('修改成功!');</script>");
                Response.Redirect("yisheng.aspx");
            }
            else
            {
                Response.Write("<script>alert('修改失败!');</script>");
            }
        }

        protected void btnBack_Click(object sender, EventArgs e)
        {
            Response.Redirect("yisheng.aspx");
        }

        protected void txtjing_TextChanged(object sender, EventArgs e)
        {

        }

        protected void btnAdd_Click(object sender, EventArgs e)
        {

        }
    }
}